-- slime_weaken
-- create by wangy
-- 概率附加禁锢状态（冈布奥专属：眩晕等）

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 专属技能等级
        local level;
        extra = extra or {};
        if extra["level"] then
            level = tonumber(extra["level"]);
        else
            local prop = PropM.combine(source, "gain_slime_skill", para[1]);
            level = PropM.apply(prop, 0);
        end

        --概率不附加状态
        local rate = para[4] * level;
        local rand = DungeonM.getRandSeed("slime_weaken") % 1000;
        if rand > rate then
            return {};
        end

        local effectRound = -1;
        extra = extra or {};
        local lastRound = extra.lastRound;

        if type(lastRound) == "number" then
            effectRound = round + lastRound + 1;
        elseif para[5] > 0 then
            -- 提升回合
            lastRound = para[5];
            local prop = PropM.combine(source, "skill_force_add", skillId);
            if prop[3] > 0 then
                lastRound = PropM.apply(prop, para[5]);
            end

            effectRound = round + lastRound + 1;
        end

        -- 如果是boss
        -- if target:isBoss() then
        --     effectRound = round + 1 + 1;
        -- end

        local condition = {
            ["id"] = para[3],
            ["end_round"] = effectRound,
        };

        -- 如果不免疫该技能，附加状态
        if SkillM.immunitySkill(source, target, skillId) then
            SkillM.getSequence(target):immunity(source, target, skillId);
        else
            CombatStatusM.applyStatus(target, para[2], condition);
        end

        -- 返回作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), arr[2], tonumber(arr[3]), tonumber(arr[4]), tonumber(arr[5]),};
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 专属技能等级
        local prop = PropM.combine(source, "gain_slime_skill", para[1]);
        local level = PropM.apply(prop, 0);

        -- 技能效果
        local rate = para[4] * level;
        desc = string.gsub(desc, "{slime_weaken}", rate / 10);

        -- 回合数
        local round = para[5];

        -- 提升回合
        local prop = PropM.combine(source, "skill_force_add", skillId);
        if prop[3] > 0 then
            round = PropM.apply(prop, round);
        end

        desc = string.gsub(desc, "{round}", round);

        return desc;
    end,
};
